<?php

namespace app\api\controller\baiying;


use app\common\exception\UploadException;
use think\Config;
use think\Hook;
use baiying\lib\BYTokenClient;
use think\Db;

/**
 * 公共接口
 */
class Byfenxi extends Bybase {

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';

    public function _initialize() {
        parent::_initialize();
    }
    
    public function autoFenYeGetTaskPhone(){
        ignore_user_abort(true);    // 忽略客户端断开
        set_time_limit(0);        //设置执行不超时
        ini_set('memory_limit', '3096M');

        $num = 100;
        $page = 0;
        while (true){
            $list = db(getBaiYingDataTable())->where("is_yixiang = 0")->limit($num*$page,$num)->select();
            foreach ($list as $value){
                $config = json_decode($value['config'],true);
                $resultList = $config['resultList'];
                if(!empty($resultList[0]['name']) && $resultList[0]['name'] == '客户意向等级'){
                    preg_match('/[a-zA-Z]/', $resultList[0]['value'], $matches);
                    db(getBaiYingDataTable())->where("id",$value['id'])->update([
                        'is_yixiang'=>1,
                        'yixiang_txt'=>$resultList[0]['value'],
                        'yixiang_value'=> !empty($matches[0])?$matches[0]:'',
                    ]);
                }
            }
//            usleep() 函数延迟执行当前脚本若干微秒（一微秒等于一百万分之一秒）。 延迟5秒
            usleep(5000000);
            
        }
    }

    

}
